package de.tudarmstadt.ukp.muip.fibqdojo.japanese;

import de.tudarmstadt.ukp.muip.fibqdojo.interfaces.IFIBQToken;
import de.tudarmstadt.ukp.muip.fibqdojo.interfaces.IStructureVisitor;

/**
 * This JapaneseToken class accounts for the used preprocessing tool that was
 * used during development (MeCab). The tool provided morpheme level output,
 * hence no words but morphemes were provided. Each token is hence represented
 * as a set of one or more morphemes of which each had a lemma, part of speech
 * and a kana writing provided.
 * 
 * @author Tobias Horsmann
 */
public class JapaneseToken implements IFIBQToken {

    private final String[] partOfSpeech;
    private final String[] forms;
    private final String[] lemma;
    private final String[] kana;
    private final String[] dan;
    private final String[] kei;

    /**
     * If <code>true</code>, the kana-reading is returned
     */
    private boolean simplify;

    /**
     * Creates a Japanese token comprising of one or more morphemes with meta
     * information about those morphemes. It is assumed that the arrays are of
     * same size and that the content at index i contains information about the
     * same morpheme
     */
    public JapaneseToken(String[] forms, String[] partOfSpeech, String[] lemma, String[] kana, String[] kei,
            String[] dan) {
        this.forms = forms;
        this.partOfSpeech = partOfSpeech;
        this.lemma = lemma;
        this.kana = kana;
        this.dan = dan;
        this.kei = kei;
    }

    /**
     * The part of speech tags contain fine grained tagging information that are
     * separated by <b>-</b>. The character sequence at index 0, before the
     * first <i>-</i> occurs, names the word class of the token. Subsequently
     * information at index 0 and the information contained at higher index only
     * contain (quite fine grained) additional information. The part of speech
     * tags at index 1 or larger refer to the morpheme rather than to the token
     * or the word. Hence, according to index 0 a token is word, while the pos
     * information for the morpheme at index 1 states that are morpheme is an
     * auxiliary verb
     */
    public String[] getPartOfSpeech() {
        return partOfSpeech;
    }

    public String[] getForms() {
        return forms;
    }

    public String[] getLemma() {
        return lemma;
    }

    public String[] getKana() {
        return kana;
    }

    /**
     * The <i>~kei</i> refers to one of six conjugation forms in Japanese. 未然形
     * (Mizenkei), 志向形 (Shikōkei), 連用形 (Renyōkei), 終止形/連体形
     * (Shūshikei/Rentaikei), 仮定形 (Rentaikei), 命令形 (Meireikei)
     */
    public String[] getKei() {
        return kei;
    }

    /**
     * Contains any kind of meta data. Currently only filled for the first
     * morpheme of a verb stating whether it is an ichidan or godan verb
     */
    public String[] getDan() {
        return dan;
    }

    @Override
    public void accept(IStructureVisitor visitor) {
        visitor.visit(this);
    }

    public void setSimplify(boolean simplify) {
        this.simplify = simplify;
    }

    public boolean isMarkedSimplified() {
        return simplify;
    }

    @Override
    public String toString() {
        String text = "";
        for (String form : forms) {
            text += form;
        }
        String[] split = partOfSpeech[0].split("-");
        text += "_" + split[0];
        return text;
    }

}
